<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;


/* @var $this yii\web\View */
/* @var $model backend\modules\pooai\models\ZpooaiPages */

$this->title = Yii::t('app', '查看订单详情');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', '订单详情'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$this->registerCssFile('@web/css/admin.css');
$this->registerCssFile('@web/css/jquery.dad.css');
$this->registerJsFile('@web/js/jquery.dad.min.js');
?>
<style>
    td,th{
        padding: 20px;
        border: 1px  solid beige;
        text-align: center;;
    }
</style>
<div class="zpooai-pages-create" style="background-color: white;width: 100%;height: 100%;">
    <div class="zpooai-pages-form" >
        <div class="nav-ul-li">
            <ul class="nav-ul">
                <li id="aPage01" class="nav-li nav-li-active" style="margin-left:0px !important;">
                    <a  data-toggle="tab"><i class="glyphicon glyphicon-th-large"></i>基本信息</a>
                </li>
                <li id="aPage02" class="nav-li" >
                    <a  data-toggle="tab"><i class="glyphicon glyphicon-edit"></i>物流设置</a>
                </li>
                <li id="aPage03" class="nav-li" >
                    <a  data-toggle="tab"><i class="glyphicon glyphicon-edit"></i>付款详情</a>
                </li>
            </ul>
        </div>

        <div class="page-data-form" >
            <!--formPage01-->
            <div class="FormPage01" >
                <div class="">
                <!--基本信息-->
                    <table width="100%">
                        <thead>
                            <div style="width: 100%;height: 40px;line-height:40px;text-align: center;background-color:rgb(223,240,216);">
                                基本信息
                            </div>
                        </thead>
                        <tbody>
                            <tr>
                                <td style="width: 12.5%;text-align: right ;font-weight: bold;">订单号:</td>
                                <td style="width: 32.5%;"><?=$model->order_sn?></td>
                                <td style="width: 12.5%;text-align: right;font-weight: bold;">订单状态:</td>
                                <td style="width: 32.5%;">
                                <?php
                                    if(empty($model->order_status)){
                                        echo "未支付";
                                    } else if($model->order_status==1){
                                        echo "已支付、待发货";
                                    }else if($model->order_status==2){
                                        echo "已支付、已发货、待收货";
                                    }else if($model->order_status==3){
                                        echo "待评价";
                                    }else if($model->order_status==4){
                                        echo "已评价";
                                    }else if($model->order_status==5){
                                        echo "已取消";
                                    }else if($model->order_status==6){
                                        echo "已删除";
                                    }
                                    ?>
                                </td>

                            </tr>
                            <tr>
                                <td style="width: 12.5%;text-align: right;font-weight: bold;">购货人:</td>
                                <td style="width: 32.5%;"><?=$model->consignee?></td>
                                <td style="width: 12.5%;text-align: right;font-weight: bold;">下单时间:</td>
                                <td style="width: 32.5%;"><?=$model->created_at?></td>

                            </tr>
                            <tr>
                                <td style="width: 12.5%;text-align: right;font-weight: bold;">支付方式:</td>
                                <td style="width: 32.5%;"><?=$model->pay_name?></td>
                                <td style="width: 12.5%;text-align: right;font-weight: bold;">配送方式:</td>
                                <td style="width: 32.5%;">
                                    <?php  if($model->shipping_id) { ?>
                                        <?=$model->shipping_name?><br /><button onclick="javascript:showWuliu('<?=$model->order_id?>')" class="btn btn-success">查看物流</button></td>
                                    <?php } else { ?>
                                        <a onclick="javacript:changeFormPage02()">去发货</a>
                                    <?php }?>
                            </tr>

                        </tbody>
                    </table>
                    <!--基本信息END-->

                    <!--购货人信息-->
                    <table width="100%">
                        <thead>
                            <div style="width: 100%;height: 40px;line-height:40px;text-align: center;background-color:rgb(223,240,216);">
                                购货人信息
                            </div>
                        </thead>
                        <tbody>
                        <tr>
                            <td style="width: 12.5%;text-align: right;font-weight: bold;">购货人名称:</td>
                            <td style="width: 32.5%;"><?=$model->consignee?></td>
                            <td style="width: 12.5%;text-align: right;font-weight: bold;">地址:</td>
                            <td style="width: 32.5%;"><?= "【".$model->country_name."】" ."【".$model->province_name."】". "【".$model->city_name."】". $model->district_name."】".$model->address?></td>

                        </tr>
                        <tr>
                            <td style="width: 12.5%;text-align: right;font-weight: bold;">电话:</td>
                            <td style="width: 32.5%;"><?=$model->mobile?></td>
                            <td style="width: 12.5%;text-align: right;font-weight: bold;">最佳送货时间:</td>
                            <td style="width: 32.5%;"><?=$model->best_time?></td>

                        </tr>
                        </tbody>
                    </table>
                    <!--购货人信息END-->

                    <!--货物信息-->
                    <table width="100%">
                        <thead >
                        <div style="width: 100%;height: 40px;line-height:40px;text-align: center;background-color:rgb(223,240,216);">
                            货物信息
                        </div>
                        </thead>
                        <tbody>
                        <th>商品名称:</th>
                        <th>货号</th>
                        <th>商品市场价格:</th>
                        <th>商品本店价格:</th>
                        <th>购买数量:</th>
                        <th>库存:</th>
                        <th>小计</th>
                            <?php
                                static $orderAmount = 0;
                                foreach($orderGoods as $k=>$v) {?>
                                <tr>
                                    <td ><?=$v->goods_name?></td>
                                    <td><?= $v->goods_sn?></td>
                                    <td ><?= $v->market_price?></td>
                                    <td ><?=$v->goods_price?></td>
                                    <td ><?=$v->goods_number?></td>
                                    <td ><?=$v->send_number?></td>
                                    <td ><?=$v->goods_number*$v->goods_price?></td>
                                </tr>
                                <?php $orderAmount += $v->goods_number*$v->goods_price?>
                            <?php }?>
                            <tr >
                                <td></td><td></td><td></td><td></td><td></td><td></td>
                                <td >
                                    <?=$orderAmount?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <!--货物信息-->
                </div>
            </div>
            <!--formPage01END-->

            <!--formPage02-->
            <?php $form = ActiveForm::begin(); ?>
            <div class="FormPage02" style="display: none">
                <input id="Is_shipping" type="hidden" value="<?=$model->shipping_id?>">
                <table width="100%">
                    <thead>电子面单下单</thead>
                    <th></th>
                    <th>物流公司名称:</th>
                    <th>物流公司号:</th>
                    <th>物流单号:</th>
                    <?php
                    foreach($shippingARR as $k=>$v) {?>
                        <tr>
                            <?php if($v['is_downshipping']) { ?>
                                <td >
                                    <?php if(isset($v['check'])&&$v['check']==1) { ?>
                                        <input class="downshipping" name="radio_shipping_id" type="radio" value="<?=$v['shipping_id']?>" checked >
                                    <?php } else {?>
                                        <input class="downshipping" name="radio_shipping_id" type="radio" value="<?=$v['shipping_id']?>">
                                    <?php } ?>
                                </td>

                                <td ><?=$v['shipping_name']?></td>
                                <td><?= $v['shipping_code']?></td>
                                <td>
                                    <?php if(isset($v['invoice_no'])) { ?>
                                        <input name="<?=$v['shipping_id']?>" type="text" value="<?=$v['invoice_no']?>"  >
                                        <div><?=$model->shopping_temp?></div>
                                    <?php } ?>
                                </td>

                            <?php } ?>
                        </tr>
                    <?php }?>
                </table>

                <table width="100%">
                    <thead>非电子面单下单</thead>
                    <th></th>
                    <th>物流公司名称:</th>
                    <th>物流公司号:</th>
                    <th>物流单号:</th>
                    <?php
                    foreach($shippingARR as $k=>$v) {?>
                        <tr>
                            <?php if(!$v['is_downshipping']) { ?>
                                <td >
                                    <?php if(isset($v['check'])&&$v['check']==1) { ?>
                                        <input class="notdownshipping" name="radio_shipping_id" type="radio" value="<?=$v['shipping_id']?>" checked >
                                    <?php } else {?>
                                        <input class="notdownshipping" name="radio_shipping_id" type="radio" value="<?=$v['shipping_id']?>">
                                    <?php } ?>
                                </td>

                                <td ><?=$v['shipping_name']?></td>
                                <td><?= $v['shipping_code']?></td>
                                <td>
                                    <?php if(isset($v['invoice_no'])) { ?>
                                        <input id="<?=$v['shipping_id']?>" name="<?=$v['shipping_id']?>" type="text" value="<?=$v['invoice_no']?>"  >
                                    <?php } else {?>
                                        <input id="<?=$v['shipping_id']?>" name="<?=$v['shipping_id']?>" type="text" >
                                    <?php } ?>
                                </td>

                            <?php } ?>
                        </tr>
                    <?php }?>
                </table>
            </div>
            <div class="form-group">
                <div onclick="javascript:ajaxShipping()" class="btn btn-primary">确定修改</div>
            </div>
            <input id="order_id" type="hidden" value="<?=$model->order_id?>">
            <input type="hidden" name="_csrf" id='csrf' value="<?= Yii::$app->request->csrfToken ?>">
            <?php $form = ActiveForm::end(); ?>
            <input type="hidden" id = 'FormPageType' value="<?=$FormPage?>" >
            <!--formPage02END-->
        </div>
    </div>
</div>

<script>
    $('.nav-li').mouseover(function(){
        $(this).css('background-color','rgb(250,250,250)')
    });
    $('.nav-li').mouseout(function(){
        $(this).css('background-color','rgb(245,245,245)')
    });
    $('.nav-li').click(function(){
        $('.nav-li').removeClass('nav-li-active');
        $(this).addClass('nav-li-active');

        var pageNumber = $(this)[0].id;
        if(pageNumber=='aPage01') {
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","block");
            $('#form-group-submit-btn').css("display","block");

        }  else if(pageNumber=="aPage02"){
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","block");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","block");

        } else if(pageNumber=="aPage03"){
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","block");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","block");

        }else if(pageNumber=="aPage04"){
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","block");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","none");

        }else if(pageNumber=="aPage05"){
            $('.FormPage05').css("display","block");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","none");

        }

    });

    var FormPageType= $('#FormPageType').val();
    switch (FormPageType){
        case 'FormPage01':
            $('.nav-li').removeClass('nav-li-active');
            $('#aPage01').addClass('nav-li-active');
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","block");
            $('#form-group-submit-btn').css("display","block");
            break;
        case 'FormPage02':
            $('.nav-li').removeClass('nav-li-active');
            $('#aPage02').addClass('nav-li-active');
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","block");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","block");
            break;
        case 'FormPage03':
            $('.nav-li').removeClass('nav-li-active');
            $('#aPage03').addClass('nav-li-active');
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","block");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","block");
            break;
        case 'FormPage04':
            $('.nav-li').removeClass('nav-li-active');
            $('#aPage04').addClass('nav-li-active');
            $('.FormPage05').css("display","none");
            $('.FormPage04').css("display","block");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","none");
            break;
        case 'FormPage05':
            $('.nav-li').removeClass('nav-li-active');
            $('#aPage05').addClass('nav-li-active');
            $('.FormPage05').css("display","block");
            $('.FormPage04').css("display","none");
            $('.FormPage03').css("display","none");
            $('.FormPage02').css("display","none");
            $('.FormPage01').css("display","none");
            $('#form-group-submit-btn').css("display","none");
            break;
    }

    function changeFormPage02()
    {
        $('.nav-li').removeClass('nav-li-active');
        $('#aPage02').addClass('nav-li-active');
        $('.FormPage05').css("display","none");
        $('.FormPage04').css("display","none");
        $('.FormPage03').css("display","none");
        $('.FormPage02').css("display","block");
        $('.FormPage01').css("display","none");
        $('#form-group-submit-btn').css("display","block");
    }

</script>

<script>
    function ajaxShipping()
    {
        //物流ID原值
        var order_shippingid= $('#Is_shipping').val();
        //选中input框
        var shippingChecked = $('input[name=radio_shipping_id]:checked');
        //物流ID新值
        var new_shippingid = shippingChecked.val();

        var className = shippingChecked[0].className;

        if(className=='downshipping'){
            //电子物流面单下单
            ajaxTodoDown(order_shippingid,new_shippingid);
            return ;
        } else if(className=='notdownshipping') {
            //非电子物流面单下单
            var inov = $("#"+shippingChecked.val()+"");
            if(inov.val()){
                ajaxTodo(inov.val(),order_shippingid,new_shippingid);
                return ;
            }else{
                alert('物流编号不能为空');
                return ;
            }
        }
    }

    //非电子面单ajax
    function ajaxTodo(inoval,order_shippingid,new_shippingid)
    {
        var order_id = $("#order_id").val();
        var csrf  = $('#csrf').val();
        $.ajax({
            url: '?r=orders/orderinfo/shiptochange',
            type: 'post',
            data: {_csrf:csrf,order_id:order_id,inoval:inoval,order_shippingid:order_shippingid,new_shippingid:new_shippingid},
            success: function (data) {
                var mes = eval('('+data+')');
                if(mes[0]) {
                }else{
                    alert(mes[1]);
                }
                return;
            }
        })
    }


    //电子面单ajax
    function ajaxTodoDown(order_shippingid,new_shippingid)
    {
        var order_id = $("#order_id").val();
        var csrf  = $('#csrf').val();
        $.ajax({
            url: '?r=orders/orderinfo/downtoadd',
            type: 'post',
            data: {_csrf:csrf,order_id:order_id,order_shippingid:order_shippingid,new_shippingid:new_shippingid},
            success: function (data) {
                var mes = eval('('+data+')');
                if(mes[0]) {
                }else{
                    alert(mes[1]);
                }
                return;
            }
        })
    }
</script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    物流轨迹
                </h4>
            </div>
            <div class="modal-body" style="height: 800px;">

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    function showWuliu(order_id)
    {
        var csrf  = $('#csrf').val();
        $.ajax(
            {
                url: '?r=orders/orderinfo/showwuliu',
                type: 'post',
                data: {_csrf:csrf,order_id:order_id},
                success: function (data) {
                    var mes = eval('('+data+')');
                    if(mes[0]) {
                        $('#myModal').modal({
                            keyboard: true
                        });
                        var str = '';
                        if(mes[1].Success==true){
                            var Traces = mes[1].Traces;
                            for(var i=0;i<Traces.length;i++){
                                str += Traces[i].AcceptTime;
                                str += Traces[i].AcceptStation+"<br />";
                            }
                            $(".modal-body").html (
                                str);
                        } else{
                            $(".modal-body").html (
                                "物流已过期");
                        }
                    }else{
                        alert(mes[1]);
                    }
                    return;
                }
            }
        )
    }
</script>

